<?php defined('SYSPATH') or die('No direct script access.');

class Controller_Main extends Controller_Template{

	public function before() {
		parent::before();
		
		$this->config = Kohana::$config->load('settings');
		$this->template->path_style = $this->config['path_to_css'];
		$this->template->path_js = $this->config['path_to_js'];
		$this->template->styles = array();
		$this->template->js = array();
		
				
		$this->template->styles[] = 'style.css';
		$this->template->styles[] = 'jquery.fancybox-1.3.4.css';
		$this->template->styles[] = 'jPaginate.css';
	
		$this->template->js[] = 'jquery-1.4.3.min.js';
		$this->template->js[] = 'jquery.fancybox-1.3.4.pack.js';
		$this->template->js[] = 'page.js';
		$this->template->js[] = 'jquery.paginate.js';
		$this->template->js[] = 'full.js';
	
	}

	public function action_index(){
		$images = ORM::factory('image');		
		$count = $images->count_all();
		if($count !== 0){
			$page = ceil($count / 12);	
		}
		$img = $images->limit(12)->find_all();		
		$content = View::factory('main')
			->bind('page',$page)	
			->bind('img',$img);
		$this->template->content = $content;
	}
	
} 
